package com.example.router

import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.callback.NavigationCallback
import com.example.base.RoutePath

/**
 * 局部降级策略
 */
class LocalDegradeService constructor(private val path:String = "",private val group:String = ""):NavigationCallback{
   private  var defaultGroup:String = RoutePath.GROUP_EMPTY
    private var defaultPath:String = RoutePath.ROUTE_EMPTY

    /**
     * 匹配到目标页面
     */
    override fun onFound(postcard: Postcard?) {

    }

    /**
     * 没匹配到
     */
    override fun onLost(postcard: Postcard) {
        if(!path.isNullOrEmpty()){
            defaultPath = path
        }
        if(!group.isNullOrEmpty()){
            defaultGroup = group
        }
        postcard.path = defaultPath
        postcard.group = defaultGroup
        postcard.navigation()
    }

    /**
     * 成功跳转
     */
    override fun onArrival(postcard: Postcard?) {

    }

    /**
     * 失败
     */
    override fun onInterrupt(postcard: Postcard?) {

    }
}